- /* sdfddcmp.cpp by K.Tsuru */
- // function ID = 320 DRADIX
- /********************************************************
- SDouble class
- compare |m| and |n| within CurrentMaxSize()
- |m| > |n| return 1
- |m| == |n| return 0
- |m| < |n| return -1
- It regards 0.3141592653589 == 0.314159(CurrentMaxSize()).
- *********************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- int DDCompare(const SDouble& m, const SDouble& n){
- // m = 0 || n = 0
- if(!m.Sign(320) || !n.Sign(320)) return abs(m.Sign()) - abs(n.Sign());
- if(&m == &n) return 0; // same object
- if(m.Type() != n.Type()) m.SetError(m.RADIX_ERR, "DDCompare", 320);
- //different in exponent of the standard form
- if( m.NetRdxExp() != n.NetRdxExp() ) return ( m.NetRdxExp() > n.NetRdxExp() ) ? 1 : -1;
- //here same in NetRdxExp()
- //Last() < CurrentMaxSize()
- int mf = (int)m.First(), ml = (int)m.Last();
- int nf = (int)n.First(), nl = (int)n.Last();
- SDouble temp;
- const fType* mv;
- const fType* nv;
- /***************************************************
- In the fixed point mode it may be diffrent in rdxExp.
- ****************************************************/
- //adjust the position of figures
- if(mf < nf){
- mv = m.ReadFigures();
- //shift n to upper
- temp = n; temp.ShiftArray(mf - nf);
- nv = temp.ReadFigures(); nl = (int)temp.Last();
- } else if(mf > nf){
- nv = n.ReadFigures();
- //shift m to upper
- temp = m; temp.ShiftArray(-mf + nf);
- mv = temp.ReadFigures(); ml = (int)temp.Last();
- } else {
- //Almost m.rdxExp == n.rdxExp and comes here.
- mv = m.ReadFigures(); nv = n.ReadFigures();
- }
- //Compare from the highest figure.
- //It is same in the top position of figures. ml, nl = figures-1
- //It cannot assert that larger figures has greater value.
- //example :0.0002*D^1 > 0.0001 999999.... *D^1
- int c = 0;
- int cf = min(mf, nf), cl = min(ml, nl); //range of comparison
- register int i;
- for(i = cf; i <= cl; i++){
- if( mv[i] != nv[i] ){
- c = (mv[i] > nv[i]) ? 1 : -1; break;
- }
- }
- if(c) return c;
- if( ml == nl ) return 0; //same figures
- return ml > nl ? 1 : -1; //larger figures is greater 0.21 > 0.2
- }
sdfddcmp.cpp : last modifiled at 2017/03/13 14:31:58(2,153 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).